<?php
/**
 * @version			$Id$
 * @author			Richard Asp
 * @package			Joomla
 * @subpackage		gnudoor
 * @copyright		(C) 2010 gnudoor LLC
 * @license      GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * See COPYRIGHT.php for copyright notices and details.
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.controller');

class GnudoorControllerAppt extends GnudoorController
{
	
	function display() {
		JRequest::setVar( 'view', 'appt' );
		JRequest::setVar( 'layout', 'default');
		parent::display();
    }

    function change_test() {
    	$model =& $this->getModel('Appt');
		$direction = JRequest::getVar('direction');
		$firstday = JRequest::getVar('fdate');
	
    	if (function_exists('date_create')) {
			$firstday = $model->getStartDate('wday',$firstday);
    		if ($direction == 'right') {
				$fd = date_format($firstday->modify('+7 day'),'Y-m-d');
			} elseif ($direction == 'left') {
				$fd = date_format($firstday->modify('-7 day'),'Y-m-d');
			} else {
				$fd = date_format($firstday,'Y-m-d');
			}
    	} else {
    		$hr = date('H');
    		$min = date('i');
    		$sec = date('s');
    		$pieces = explode("-", $firstday);
    		$timestamp = mktime($hr,$min,$sec,$pieces[1],$pieces[2],$pieces[0]);
			$arr = getdate($timestamp);

			$jd = $arr['yday'];
			$currday = getdate();
	        $tjd = $currday['yday'];
    		
			if ($direction == 'right') {
				$timestamp += 604800;
				$fd = strftime('%Y-%m-%d',$timestamp);
			} elseif ($direction == 'left') {
				$timestamp -= 604800;
				$fd = strftime('%Y-%m-%d',$timestamp);
			} else {
				$timestamp += 604800;
				$fd = strftime('%Y-%m-%d',$timestamp);
			}
    	}
		
		JRequest::setVar( 'fd', $fd );
    	JRequest::setVar( 'view', 'appt' );
		JRequest::setVar( 'layout', 'default');
		parent::display();
	}
	
	function verify() {
		JRequest::setVar( 'message','Verification sent by email');
		JRequest::setVar( 'returnLink','index.php?option=com_gnudoor&controller=newtask&task=thanks');	
		JRequest::setVar( 'returnMessage','Click here to simulate validating your email');
		JRequest::setVar( 'view', 'appt' );
		JRequest::setVar( 'layout', 'notice');
		parent::display();
	}

	function validated() {
		JRequest::setVar( 'message','Thank you for your order');
		JRequest::setVar( 'returnLink','index.php?option=com_gnudoor&controller=newtask&task=thanks');	
		JRequest::setVar( 'returnMessage','Continue');
		JRequest::setVar( 'view', 'appt' );
		JRequest::setVar( 'layout', 'notice');
		parent::display();
	}
	
	function create() {
		$reservationdate = JRequest::getVar('rdate');
		$reservationslot = JRequest::getVar('rslot');
		JRequest::setVar( 'view', 'appt' );
		JRequest::setVar( 'layout', 'reserve');
		parent::display();
	}

	function selectservice() {
		JRequest::setVar( 'view', 'appt' );
		JRequest::setVar( 'layout', 'selectservice');
		parent::display();
	}
	
}

?>